package org.rcy.ruicingmarket.service;

import org.rcy.framework.api.email.EmailSender;
import org.rcy.framework.api.sms.SMSSender;
import org.rcy.framework.api.sms.SMSTemplate;
import org.rcy.ruicingmarket.vo.SMSParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 吴康桥
 * @Description
 * @date 2022/11/24 9:32
 */

@Service
public class MessageService {
	@Autowired
	private List<SMSSender> smsSenders;
	@Autowired
	private List<EmailSender> emailSenders;

	public void sendSms(SMSParam param) throws Exception {
		String content = param.getContent();
		String target = param.getTarget();
		Object template =  param.getT();

		for (SMSSender smsSender : smsSenders) {
			if(smsSender.support(template)){
				smsSender.send(target,content,(SMSTemplate) template);
			}
		}
	}

}
